<template>
  <div class="homepage" v-show="showFlag">
    <div class="homepage-content">
      <div class="homepage-top">
        <div class="member-info">
          <store-info :store-info="storeInfo" @getStoreInfo="_getStoreInfo" />
          <attets-panel
            class="card-panel"
            :account-info="accountInfo"
            @getAccountAgain="_getAccount"
          />
        </div>
        <panel-group :account-info="accountInfo" />
      </div>
      <div class="homepage-center">
        <cost :account-info="accountInfo" />
      </div>
      <div class="homepage-bottom">
        <calendar></calendar>
        <IncomeChart />
      </div>
    </div>
    <entryDialog v-if="entryFlag" />
  </div>
</template>
<script>
import StoreInfo from "./components/info";
import PanelGroup from "./components/PanelGroup";
import AttetsPanel from "./components/assetsPanel";
import Cost from "./components/cost";

import Calendar from "./components/calendar";
import IncomeChart from "./components/incomeChart";
import entryDialog from "./components/entryDialog";
import { mapGetters } from "vuex";
import { getStoreInfo, getAccount } from "@/api/homepage";

import { setToken, removeToken } from "@/utils/auth";
import { GetRequest } from "@/utils";

const lineChartData = {
  expectedData: [100, 120, 161, 134, 105, 160, 165],
  actualData: [120, 82, 91, 154, 162, 140, 145],
};

export default {
  data() {
    return {
      showFlag: false,
      storeInfo: {},
      accountInfo: {},
      lineChartData: lineChartData,
      entryFlag: false,
    };
  },
  created() {
    // console.log("是否代理商", this.memberInfo.status);
    if (this.memberInfo.status == 1) {
      this.showFlag = true;
      this._getStoreInfo();
      this._getAccount();
      if (window.performance.navigation.type == 1) {
        console.log("页面被刷新");
      } else {
        console.log("首次被加载");
        this.entryFlag = true;
        setTimeout(() => {
          window.location.reload();
        }, 1000);
        setTimeout(() => {
          this.entryFlag = false;
        }, 2000);
      }
    } else {
      if (this.memberInfo.is_auth == 1) {
        this.$message.error("您还没有加入云木屋，正在为您跳转");
        setTimeout(() => {
          // this.$router.push({ name: "contractServices" });
          window.location.href =
            process.env.VUE_APP_BASE_MEMBER + "/member/agent/agent";
        }, 2000);
      } else {
        this.$message.error("您还没有加入云木屋，正在为您跳转");
        setTimeout(() => {
          // this.$router.push({ name: "explain" });
          window.location.href =
            process.env.VUE_APP_BASE_MEMBER + "/member/agent/agent";
        }, 2000);
      }
    }
  },
  computed: {
    ...mapGetters(["memberInfo"]),
  },
  methods: {
    _getStoreInfo() {
      getStoreInfo().then((res) => {
        this.storeInfo = res.data;
        console.log("店铺信息", this.storeInfo);
        this.$store.commit("user/SET_STOREINFO", this.storeInfo);
      });
    },
    _getAccount() {
      getAccount().then((res) => {
        this.accountInfo = res.data;
      });
    },
  },
  components: {
    StoreInfo,
    PanelGroup,
    AttetsPanel,
    Cost,
    Calendar,
    IncomeChart,
    entryDialog,
  },
};
</script>


<style lang="scss" scoped>
.homepage {
  width: 100%;
  height: 100%;
  padding: 20px;
  overflow: auto;
  .homepage-content {
    min-width: 1400px;
    .homepage-top {
      display: flex;
      margin-bottom: 20px;
      width: 100%;
      height: 260px;
      justify-content: space-between;
      .member-info {
        display: flex;
        background: #fff;
        width: 53.8%;
      }
      .panel-group {
        width: 45%;
        font-size: 0;
      }
    }
    .homepage-bottom {
      height: 550px;
      display: flex;
      justify-content: space-between;
      margin-bottom: 40px;
      .calendar-wrapper {
      }
    }
  }
}
</style>